import { Component } from '@angular/core';
import { Order } from './order';

import { OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { OrderService } from './order.service';

@Component({
  selector: 'my-orders',
  templateUrl: './order.component.html'
})

export class OrderComponent implements OnInit {
  ngOnInit() {
    this.getOrders();
  }

  orders: Order[];
  selectedOrder: Order;

  start_time = new Date().toDateString();
  end_time = new Date().toDateString();

  onSelect(order: Order) { this.selectedOrder = order; }

  constructor(
    private router: Router,
    private orderService: OrderService) {
  }

  getOrders() {
    this.orderService.searchOrders(this.start_time, this.end_time).then(orders => this.orders = orders);
  }

  search() {
    this.getOrders();
  }
}
